package com.ukao.cashregister.adapter;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.mcxtzhang.commonadapter.rv.CommonAdapter;
import com.mcxtzhang.commonadapter.rv.ViewHolder;
import com.ukao.cashregister.R;
import com.ukao.cashregister.bean.OrderQuiryTabeleBean;
import com.ukao.cashregister.listener.OnItemChildClickListener;
import com.ukao.cashregister.utils.CheckUtils;
import com.ukao.cashregister.utils.ImageUtils;
import com.ukao.cashregister.utils.MyDateUtils;
import com.ukao.cashregister.widget.ShapedImageView;
import com.ukao.cashregister.widget.StateButton;

import java.util.Date;
import java.util.List;


import static com.ukao.cashregister.R.id.enter_potpocket_btn;
import static com.ukao.cashregister.R.id.gather_btn;
import static com.ukao.cashregister.R.id.model;
import static com.ukao.cashregister.R.id.storage_btn;
import static com.ukao.cashregister.R.id.transNo_btn;
import static com.ukao.cashregister.utils.MyDateUtils.getTime;
import static com.ukao.cashregister.utils.MyDateUtils.stringDate;

/**
 * Created by ukaodev on 2017/6/14.
 */

public class OrderQuiryAdapter extends CommonAdapter<OrderQuiryTabeleBean.ListBean> {




    public OrderQuiryAdapter(Context context, List<OrderQuiryTabeleBean.ListBean> datas) {
        super(context, datas, R.layout.adapter_order_quiry1);
    }

    private OnItemChildClickListener mOnItemChildClickListener;
    public  void  setOnItemChildClickListener(OnItemChildClickListener mOnItemChildClickListener){
        this.mOnItemChildClickListener=mOnItemChildClickListener;
    }




    @Override
    public void convert(final  ViewHolder viewHolder, OrderQuiryTabeleBean.ListBean item) {


        TextView factoryTransNo = viewHolder.getView(R.id.factoryTransNo);
        TextView paymentPrice = viewHolder.getView(R.id.paymentPrice);
        TextView createTime = viewHolder.getView(R.id.createTime);
        TextView orderNo = viewHolder.getView(R.id.orderNo);
        ShapedImageView headimgPath = viewHolder.getView(R.id.headimgPath);
        TextView userName = viewHolder.getView(R.id.userName);
        TextView takeMode = viewHolder.getView(R.id.takeMode);
        TextView sendMode = viewHolder.getView(R.id.sendMode);
        TextView statusText = viewHolder.getView(R.id.statustext);
        TextView userPhone = viewHolder.getView(R.id.userPhone);
        TextView takeDate = viewHolder.getView(R.id.takeDate);
        TextView sendDate = viewHolder.getView(R.id.sendDate);
        TextView payStatus = viewHolder.getView(R.id.payStatus);
        TextView cardNo = viewHolder.getView(R.id.cardNo);
        Button gatherBtn = viewHolder.getView(R.id.gather_btn);
        TextView takeWorkName = viewHolder.getView(R.id.takeWorkName);
        TextView sendWorkName = viewHolder.getView(R.id.sendWorkName);
        TextView originText = viewHolder.getView(R.id.originText);
        StateButton transNoBtn = viewHolder.getView(R.id.transNo_btn);
        StateButton storageBtn = viewHolder.getView(R.id.storage_btn);
        StateButton invalidBtn = viewHolder.getView(R.id.invalid_btn);
        StateButton receiptBtn = viewHolder.getView(R.id.receipt_btn);
        StateButton remarkBtn = viewHolder.getView(R.id.remark_btn);
        StateButton menterPotpocketbtn = viewHolder.getView(R.id.enter_potpocket_btn);

        TextView userRemark = viewHolder.getView(R.id.userRemark);
        TextView remark = viewHolder.getView(R.id.remark);
        receiptBtn.setVisibility(item.isEnablePrint()?View.VISIBLE: View.GONE);
        userRemark.setVisibility(CheckUtils.isEmpty(item.getUserRemark())?View.GONE: View.VISIBLE);
        remark.setVisibility(CheckUtils.isEmpty(item.getRemark())?View.GONE: View.VISIBLE);
        remark.setText("管理备注："+CheckUtils.isEmptyString(item.getRemark()));
        userRemark.setText("用户备注："+CheckUtils.isEmptyString(item.getUserRemark()));
        createTime.setText(MyDateUtils.formatDateCustom(item.getCreateTime(),"yyyy/MM/dd HH:mm:ss"));
        ImageUtils.loadImage(mContext,item.getHeadimgPath(),headimgPath);
        orderNo.setText(CheckUtils.isEmptyString(item.getOrderNo()));
        userName.setText(CheckUtils.isEmptyString(item.getUserName()));
        userPhone.setText(CheckUtils.isEmptyString(item.getUserPhone()));//getPayablePrice
        paymentPrice.setText("金额："+CheckUtils.isEmptyNumber(item.getPayablePrice())+"元");
        takeMode.setText(CheckUtils.isEmptyString(item.getTakeModeText()));
        sendMode.setText(CheckUtils.isEmptyString(item.getSendModeText()));
        if(!CheckUtils.isEmpty(item.getTakeDate())){
            Date takeDateTime = stringDate(item.getTakeDate(), "yyyy-MM-dd");
            takeDate.setText("预约取件："+getTime(takeDateTime, "MM—dd EEE")+item.getTakeTimeStart()+"-"+item.getTakeTimeEnd());
        }else{
            takeDate.setText("");
        }

        if(!CheckUtils.isEmpty(item.getSendDate())){
            Date sendDateTime = stringDate(item.getSendDate(), "yyyy-MM-dd");
            sendDate.setText("预约送件："+getTime(sendDateTime, "MM—dd EEE"));
        }else{
            sendDate.setText("");
        }

        switch (  item.getPayStatus()){
            case 0:
                payStatus.setText(item.getPayStatusText());
                payStatus.setTextColor(mContext.getResources().getColor(R.color.warm_red));

                break;
            case 1:
                payStatus.setText(item.getPayStatusText());
                payStatus.setTextColor(mContext.getResources().getColor(R.color.green));
                storageBtn.setVisibility(View.INVISIBLE);
                break;
        }

        if (!CheckUtils.isEmpty(item.getFactoryTransNo())){
            transNoBtn.setText(R.string.modified_number);
        }
        menterPotpocketbtn.setVisibility(item.isEnableBatchIn()?View.VISIBLE:View.GONE);
        factoryTransNo.setText(CheckUtils.isEmpty(item.getFactoryTransNo())?"":"工厂运单号："+item.getFactoryTransNo());
        transNoBtn.setVisibility(item.isEnableUpdateFactoryTransNo() ? View.VISIBLE : View.GONE);
        gatherBtn.setVisibility(item.isEnablePay() ? View.VISIBLE : View.GONE);
        storageBtn.setVisibility(item.isEnableStockIn() ? View.VISIBLE : View.GONE);
        invalidBtn.setVisibility(item.isEnableDestroy() ? View.VISIBLE : View.GONE);/*S是否作废*/
        statusText.setText(!CheckUtils.isEmpty(item.getStatusText())?item.getStatusText():"");
        cardNo.setText(CheckUtils.isEmptyString(item.getCardNo()));
        takeWorkName.setText(!CheckUtils.isEmpty(item.getTakeWorkName())?"取件员："+item.getTakeWorkName():"");
        sendWorkName.setText(!CheckUtils.isEmpty(item.getSendWorkName())?"送件员："+item.getSendWorkName():"");
        originText.setText(CheckUtils.isEmptyString(item.getOriginText()));
        View.OnClickListener  OnClickListener= new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!CheckUtils.isNull(mOnItemChildClickListener))
                    mOnItemChildClickListener.onChildItemClick(v.getId(), getPosition(viewHolder));


            }

        };


        menterPotpocketbtn.setOnClickListener(OnClickListener);
        transNoBtn.setOnClickListener(OnClickListener);
        receiptBtn.setOnClickListener(OnClickListener);
         storageBtn.setOnClickListener(OnClickListener);
        invalidBtn.setOnClickListener(OnClickListener);
        remarkBtn.setOnClickListener(OnClickListener);
        gatherBtn.setOnClickListener(OnClickListener);

    }









}
